//
// Created by Administrator on 2021/6/29.
//

//给定一个Excel表格中的列名称，返回其相应的列序号。
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

class Solution {
public:
    int titleToNumber(string columnTitle) {
        /**
         * 26进制
         */
        int ans = 0;
        int base = 1;
        for (auto i = columnTitle.rbegin(); i != columnTitle.rend(); ++i) {
            ans += base * (1 + int(*i - 'A'));
            if (i != columnTitle.rend() - 1)
                base *= 26;
        }
        return ans;
    }
};

int main() {
    Solution sol;
    cout << sol.titleToNumber("AA") << endl;
    cout << sol.titleToNumber("A") << endl;
    cout << sol.titleToNumber("AB") << endl;
    cout << sol.titleToNumber("ZY") << endl;
    return 0;
}